import diff from "./diff"

export default class Component{
    constructor(props){
        this.props = props
    }
    setState(state){
        // 此方法中的this是指向子类的实例对象
        this.state = Object.assign({},this.state,state)

        // 获取最新的需要渲染的VirtualDOM
        let virtualDOM = this.render()
        // 获取旧的virtualDOM 进行Diff对比
        let oldDOM = this.getDOM()
        diff(virtualDOM,oldDOM.parentNode,oldDOM)
    }

    setDOM(dom){
        this._dom = dom
    }
    getDOM(){
        return this._dom
    }

    updateProps(props){
        this.props = props
    }

    // 生命周期函数定义  一般子组件中会进行重新声明与调用  重新声明时会有覆盖操作
    componentWillMount(){}
    componentDidMount(){}
    componentWillReceiveProps(nextProps){}
    shouldComponentUpdate(nextProps,nextState){
        return nextProps != this.props || nextState !== this.state
    }
    componentWillUpdate(nextProps,nextState){}
    componentDidUpdate(nextProps,nextState){}
    componentWillUnmount(){}
}